package com.ruoyi.web.controller.hotel;


import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hotel.domain.Room;
import com.ruoyi.hotel.domain.from.RoomFrom;
import com.ruoyi.hotel.domain.query.RoomQuery;
import com.ruoyi.hotel.domain.vo.RoomVo;
import com.ruoyi.hotel.service.RoomService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @BelongsProject: ruoyi
 * @BelongsPackage: com.ruoyi.system.controller
 * @Author: lbw
 * @CreateTime: 2025-06-20  11:45
 * @Description: TODO
 */
@RestController
@RequestMapping("/room")
public class RoomController extends BaseController {

    @Resource
    private RoomService roomService;


    @PostMapping(value = "/save")
    public AjaxResult save(@RequestBody RoomFrom room){
        Boolean save = roomService.save(room);
        return AjaxResult.success(save);
    }

    @PostMapping(value = "/update")
    public AjaxResult update(@RequestBody RoomFrom homeStayFrom){
        Boolean save = roomService.update(homeStayFrom);
        return AjaxResult.success(save);
    }

    @GetMapping(value = "/delete")
    public AjaxResult delete(Long id){
        Boolean save = roomService.deleteById(id);
        return AjaxResult.success(save);
    }

    /**
     * 获取用户列表
     */
//    @PreAuthorize("@ss.hasPermi('system:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(Room homeStay)
    {
        startPage();
        List<RoomVo> roomVos = roomService.selectList(homeStay);
        if(CollUtil.isEmpty(roomVos)){
            return getDataTable(roomVos);
        }
        return getDataTable(roomVos);
    }

    /**
     * 获取用户列表
     */
//    @PreAuthorize("@ss.hasPermi('system:room:list')")
    @PostMapping("/selectPage")
    public TableDataInfo selectPage(@RequestBody RoomQuery roomQuery)
    {
        IPage<RoomVo> iPage = roomService.selectPage(roomQuery);
        return getDataTable(iPage.getRecords());
    }




}